/*
 * Search Engine Safe Url HttpModule
 * Author: Scott Van Vliet, svanvliet@hitachiconsulting.com
 * Date: 2004-05-03
 */ 

using System;
using System.Web;

namespace Boardworks.Utilities.SearchEngineSafe
{
	/// <summary>
	/// Summary description for SesHttpModule.
	/// </summary>
	public class SesHttpModule : System.Web.IHttpModule
	{
		/// <summary>
		/// Default Constructor
		/// </summary>
		public SesHttpModule()
		{
		}

		/// <summary>
		/// Method called by the HttpApplication which is using the HttpModule
		/// </summary>
		/// <param name="application">The HttpApplication using the HttpModule</param>
		public void Init(HttpApplication application)
		{
			// Add an EventHandler for the BeginRequest event of the HttpApplication
			application.BeginRequest +=new EventHandler(Application_BeginRequest);
		}

		/// <summary>
		/// Method called when the BeginRequest event from the HttpApplication is fired off
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		public void Application_BeginRequest(object sender, EventArgs e)
		{
			HttpContext context = ((HttpApplication)sender).Context;
			context.RewritePath(SesUrlUtil.FromSesUrl(context.Request.Path));
			context.Response.Filter = new SesRequestFilter(context.Response.Filter, context);
		}

		/// <summary>
		/// Method use to dispose components used by the HttpModule
		/// </summary>
		public void Dispose()
		{
		}
	}
}
